<?php
class VideoSearch extends BaseModule
{
	

	private static $address = array(
		'youtube'	=> 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=5jrpMiTU2QQ&per_page=30&tag=',
		'tagstory'	=> 'http://rss.tagstory.com/rss/rss_feed.aspx?kind=1&value=',
		'google'	=>'http://video.google.com/videofeed?type=search&so=0&num=30&output=rss&q=',

	);

	private static $allseeAddr = array(
		'youtube' => 'http://www.youtube.com/results?search_query=',
		'tagstory' => 'http://www.tagstory.com/video/video_search.aspx?idx=1&key=',
		'google' =>'http://video.google.com/videosearch?q=',

	);

	
	public function init()
	{	
	
	}

	function request(array $a)
	{
		$site = $a['site'];
		$keyword = $a['keyword'];
		if($site == 'tagstory') {
			$keyword=  urldecode($keyword);
			$keyword =iconv('UTF-8','CP949',$keyword);
			$keyword = urlencode($keyword);
		}
		
				
		$path =self::$address[$site].$keyword;
		
		 
	 	$file = file_get_contents($path);
	
		file_put_contents($path,$file);
		$dom = new WZD_DOMDocument();
		$dom->loadXML($file);
		$allsee = $dom->createElement('allsee');
		$allsee->setAttribute('url',self::$allseeAddr[$site].$keyword);
		$first = $dom->firstChild;	
		$first->appendChild($allsee);
		$dom->output();
		
		

	}


	function close()
	{	
	}

	function saveConfig(array $a) {
		
		
		
	}
		
}
?>
